package com.demo.render;

import com.demo.Interface.ILoadTexImage;

public abstract class Texture {

    public static final int STATE_UNLOADED = 0;
    public static final int STATE_QUEUED = 1;
    public static final int STATE_LOADING = 2;
    public static final int STATE_LOADED = 3;
    public static final int STATE_ERROR = 4;

    public int mState = STATE_UNLOADED;
    public int mId;
    public int mWidth;
    public int mHeight;
    public float mNormalizedWidth;
    public float mNormalizedHeight;
//    public Bitmap mBitmap;
    public ILoadTexImage mILoadTexImage;
	TextureReference mTextureRef;
	
	public void bindTextureReference(TextureReference textureRef) {
		mTextureRef = textureRef;
	}
	
	public TextureReference getTextureReference() {
		return mTextureRef;
	}

    public boolean isCached() {
        return false;
    }

    public final void clear() {
        mId = 0;
        mState = STATE_UNLOADED;
        mWidth = 0;
        mHeight = 0;
        mNormalizedWidth = 0;
        mNormalizedHeight = 0;
//        if (mBitmap != null) {
//        	mBitmap.recycle();
//        	mBitmap = null;
//        }
        if (mILoadTexImage != null) {
        	mILoadTexImage.recycle();
        	mILoadTexImage = null;
		}
    }

    public final boolean isLoaded() {
        return mState == STATE_LOADED;
    }
    
    public final void setState(int state) {
        mState = state;
    }

    public final int getState() {
        return mState;
    }

    public final int getWidth() {
        return mWidth;
    }

    public final int getHeight() {
        return mHeight;
    }

    public final float getNormalizedWidth() {
        return mNormalizedWidth;
    }

    public final float getNormalizedHeight() {
        return mNormalizedHeight;
    }

    /** If this returns true, the texture will be enqueued. */
    protected boolean shouldQueue() {
        return true;
    }

    /** Returns a bitmap, or null if an error occurs. */
//    protected abstract Bitmap load(RenderView view);
    protected abstract ILoadTexImage load();

    public boolean isUncachedVideo() {
        return false;
    }

}
